/**
 * 
 */
package com.cdhospital.admincontroller;

import java.io.File;
import java.io.IOException;

import com.cdhospital.Utils.QiniuUtils;
import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;

/**
 * @author weirdor
 *
 */
public class Uploadcontroller extends Controller {
	
	public void index() throws IOException{
		UploadFile uf = getFile("file","name");
		 QiniuUtils qiniuUtils=new QiniuUtils();
		 String qiniuphoto=null;
		 
		 qiniuphoto =  qiniuUtils.upload(uf.getFileName(), uf.getUploadPath()
                + "//"+uf.getFileName());
		 //判断上传七牛是否成功 如果不成功以本地地址作为图片路径
		 System.out.println(qiniuphoto);
      if(qiniuphoto==null){
    	  // 拼接文件上传的完整路径
           qiniuphoto = "http://" + this.getRequest().getRemoteHost() + ":"
                  + this.getRequest().getLocalPort() + "/upload/name/"
                  + uf.getFileName();
      }
      
        this.setAttr("fileName", qiniuphoto);
        
        renderJson();
	}
	public void uploads() throws IOException {
		// 上传代码
		UploadFile uf = getFile("Filedata","keshi");
		 QiniuUtils qiniuUtils=new QiniuUtils();
		 String qiniuphoto=null;
		 
		 qiniuphoto =  qiniuUtils.upload(uf.getFileName(), uf.getUploadPath()
                + "//"+uf.getFileName());
		 //判断上传七牛是否成功 如果不成功以本地地址作为图片路径
		 System.out.println(qiniuphoto);
      if(qiniuphoto==null){
    	  // 拼接文件上传的完整路径
           qiniuphoto = "http://" + this.getRequest().getRemoteHost() + ":"
                  + this.getRequest().getLocalPort() + "/upload/keshi/"
                  + uf.getFileName();
      }
      
        this.setAttr("fileName", qiniuphoto);
        
		renderJson();
	}

}
